package com.gvsoft.analyse.order;

import org.apache.commons.lang3.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * ProjectName:gvMsgClient
 * Author: zhaoqiubo
 * Date: 15/8/7
 * Time: 下午4:49
 * Desc: 客户端指令基类
 */
public  class ClientOrder {

    protected String header;
    protected String token;
    protected String rid;
    protected String body;

    private static int newRid = 0;

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getRid() {
        return rid;
    }

    public void setRid(String rid) {
        this.rid = rid;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    /**
     * 返回报文序列号，该序列号仅作为响应的对应依据，不唯一，不可作为业务标记。
     * @return
     */
    public static String getNewRid() {
        if (newRid > 1000000000) {
            newRid = 0;
        }
        newRid++;
        return Integer.toString(newRid);
    }
    public String generateOrderStr(){

        StringBuffer sb = new StringBuffer();
        sb.append(this.getHeader());

        if(!StringUtils.isBlank(this.getRid())){
            sb.append("|").append(this.getRid());
        }
        if(!StringUtils.isBlank(this.getToken())){
            sb.append("|").append(this.getToken());
        }
        if(!StringUtils.isBlank(this.getBody())){
            sb.append("|").append(this.getBody());
        }
        return sb.toString();

    }
}
